﻿using Microsoft.AspNetCore.Authorization;

namespace Simple.WebApi.Controllers.System
{
    [Route("api/ParentChildTasks/[action]")]
    [ApiController]
    [Authorize]
    public class ParentChildTasksController : ControllerBase
    {
        public readonly ParentChildTasksService _parentChildTasksService;
        public ParentChildTasksController(ParentChildTasksService parentChildTasksService)
        {
            _parentChildTasksService = parentChildTasksService;
        }

        /// <summary>
        /// 亲子任务
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> Page([FromQuery] ParentChildTasksInputModel model)
        {
            PageResultModel<ParentChildTasksDto> data = await _parentChildTasksService.GetPageAsync(model);
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 亲子任务预览
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> Preview([FromQuery] IdInputModel models)
        {
            var data = await _parentChildTasksService.Preview(models.Id);
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 亲子任务创建
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> Add([FromBody] AddTasksInput model)
        {
            await _parentChildTasksService.AddAsync(model);
            return AppResult.Status200OK("发布成功");
        }

        /// <summary>
        /// 亲子任务修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> Edit([FromBody] TasksCreateOrUpdateInput model)
        {
            await _parentChildTasksService.UpdateAsync(model);
            return AppResult.Status200OK("更新成功");
        }


        /// <summary>
        /// 亲子任务删除
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> Delete([FromBody] List<IdInputModel> models)
        {
            await _parentChildTasksService.DeleteAsync(models.Select(m => m.Id));
            return AppResult.Status200OK("删除成功");
        }

        /// <summary>
        /// 亲子任务(家长端)
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> TasksList([FromQuery] TasksListInput model)
        {
            List<Tasks> data = await _parentChildTasksService.ParentChildTasksList(model);
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 回复(家长)
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> Release([FromBody] ReleaseInput model)
        {
            await _parentChildTasksService.Release(model);
            return AppResult.Status200OK("发布成功");
        }

        /// <summary>
        /// 任务详情(家长端)
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> TasksDetil([FromQuery] IdInputModel model)
        {
            TasksDetilDto data = await _parentChildTasksService.TasksDetil(model.Id);
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 统计(教师端)
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> CompleteStatistics([FromQuery] CompleteStatisticsInput model)
        {
            CompleteStatisticsDto data = await _parentChildTasksService.CompleteStatistics(model);
            return AppResult.Status200OK(data: data);
        }
    }
}
